package com.mcr.graduateprogram.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcr.graduateprogram.bean.GameCategory;
import com.mcr.graduateprogram.common.R;
import com.mcr.graduateprogram.service.IGameCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author graduateprogram
 * @since 2023-02-25
 */
@Api(tags = "游戏类别相关接口")
@CrossOrigin
@RestController
@RequestMapping("/graduateprogram/game-category")
public class GameCategoryController {
    @Autowired
    private IGameCategoryService iGameCategoryService;

    @GetMapping("getPage")
    @ApiOperation(value = "分页查询游戏类别")
    public R getPage(@RequestParam(value = "page")Integer page,
                     @RequestParam(value = "pageSize")Integer pageSize,
                     @RequestParam(value = "name",required = false)String name){
        Page<GameCategory> clientelePage=iGameCategoryService.getPage(page,pageSize,name);
        return R.success(clientelePage);
    }
    @ApiOperation(value = "修改某个游戏类别")////////////////删redis缓存--category
    @PostMapping("updateById")
    @CacheEvict(value = "graduationProgram",key = "'allGameCategory'")
    public R updateById(@RequestBody GameCategory gameCategory){
        return R.success(iGameCategoryService.updateGameGategoryNameById(gameCategory));
    }
    @ApiOperation(value = "添加游戏类别")////////////////删redis缓存--category
    @PostMapping("addNew")
    @CacheEvict(value = "graduationProgram",key = "'allGameCategory'")
    public R addNew(@RequestBody GameCategory gameCategory){
        return R.success(iGameCategoryService.addNewGameCategory(gameCategory));
    }
    @ApiOperation(value = "查询所有游戏类别")
    @GetMapping("getAll")////////////////存redis---category
    @Cacheable(value = "graduationProgram",key = "'allGameCategory'")
    public R getAll(){
        return R.success(iGameCategoryService.list());
    }
}
